package com.ruoyi.merchant.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.merchant.domain.CulProduct;
import com.ruoyi.merchant.service.ICulProductService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文创商品管理Controller
 * 
 * @author ruoyi
 * @date 2024-08-17
 */
@RestController
@RequestMapping("/merchant/product")
public class CulProductController extends BaseController
{
    @Autowired
    private ICulProductService culProductService;

    /**
     * 查询文创商品管理列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:product:list')")
    @GetMapping("/list")
    public TableDataInfo list(CulProduct culProduct)
    {
        startPage();
        List<CulProduct> list = culProductService.selectCulProductList(culProduct);
        return getDataTable(list);
    }

    /**
     * 导出文创商品管理列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:product:export')")
    @Log(title = "文创商品管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CulProduct culProduct)
    {
        List<CulProduct> list = culProductService.selectCulProductList(culProduct);
        ExcelUtil<CulProduct> util = new ExcelUtil<CulProduct>(CulProduct.class);
        util.exportExcel(response, list, "文创商品管理数据");
    }

    /**
     * 获取文创商品管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('merchant:product:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(culProductService.selectCulProductById(id));
    }

    /**
     * 新增文创商品管理
     */
    @PreAuthorize("@ss.hasPermi('merchant:product:add')")
    @Log(title = "文创商品管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CulProduct culProduct)
    {
        return toAjax(culProductService.insertCulProduct(culProduct));
    }

    /**
     * 修改文创商品管理
     */
    @PreAuthorize("@ss.hasPermi('merchant:product:edit')")
    @Log(title = "文创商品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CulProduct culProduct)
    {
        return toAjax(culProductService.updateCulProduct(culProduct));
    }

    /**
     * 删除文创商品管理
     */
    @PreAuthorize("@ss.hasPermi('merchant:product:remove')")
    @Log(title = "文创商品管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(culProductService.deleteCulProductByIds(ids));
    }
}
